{extend name="layout" /}
{block name="css"}
<link rel="stylesheet" href="/static/style/admin.css" media="all">{/block}
{block name="title"}自定义菜单{/block}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
            <button class="layui-btn layui-btn-normal layuiadmin-btn-tags" data-type="pub">发布</button>
        </div>
        <div class="layui-card-body">
            <table id="LAY-set-wechat-menu" lay-filter="LAY-set-wechat-menu"></table>
            <script type="text/html" id="LAY-set-wechat-menu-bar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['index', 'wechat', 'table'], function () {
        var $ = layui.$, table = layui.table, admin = layui.admin, active = {
            add: function () {
                add('添加菜单', 'wechat_menu', '600px', '400px', 'LAY-set-wechat-menu');
            },
            pub: function () {
                var checkStatus = table.checkStatus('LAY-set-wechat-menu')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                layer.confirm('确定发布吗？', function (index) {
                    admin.req({
                        url: 'wechat_menu/publish'
                        , data: {ids: checkData.map(x => {return x.id})}
                        , type: "POST"
                        , done: function (res) {
                            if (res.code === 0) {
                                layer.msg(res.message, {icon: 6});
                                table.reload('LAY-set-wechat-menu');
                                layer.close(index);
                            } else {
                                layer.msg(res.message, {icon: 5});
                            }
                        }
                    });
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
{/block}